/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.Exercise.CorrectExercise;

import com.myapp.model.notificaciones.Notificaciones;
import com.myapp.model.resueltos.Resueltos;
import com.myapp.model.tipos.Tipos;
import com.myapp.model.usuarios.Usuarios;
import com.myapp.svc.Exercise.ExerciseSvc;
import com.myapp.svc.Notifications.NotificationsSvc;
import com.myapp.svc.User.UserSvc;
import java.util.ArrayList;
import java.util.List;
import javax.management.Notification;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author jaime
 */
public class CorregirOkAction extends org.apache.struts.action.Action {

    /*
     * forward name="success" path=""
     */
    private static final String SUCCESS = "success";

    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        HttpSession session=request.getSession();
        Usuarios usr=new Usuarios();
        Usuarios usrReceptor = new Usuarios();
        Resueltos res=new Resueltos();
        ExerciseSvc exerSvc=new ExerciseSvc();
        UserSvc usrSvc=new UserSvc();
        Notificaciones not=new Notificaciones();
        NotificationsSvc notSvc = new NotificationsSvc();
        Tipos tip = new Tipos();
        List lu = new ArrayList();       
        res=exerSvc.selectExercResolvePorId(((CorrectExerciseForm)form).getIdresueltos()+"");
        res.setPuntuacion((byte)(((CorrectExerciseForm)form).getPuntuacion()));
        res.setRespuesta(((CorrectExerciseForm)form).getRespuesta());
        
        exerSvc.corregido(res);
        
        usr=res.getEjercicios().getUsuarios();
        
        usrSvc.aumentarDisponCorreg(usr);
        
        usrReceptor=res.getUsuarios();
        
        not.setUsuariosByIdemisor(usr);
        
        tip.setIdtipo(Integer.valueOf("7"));
        
        not.setTipos(tip);
        
        lu.add(usrReceptor);
        
        notSvc.sendNotifications(not, lu);
        
        return mapping.findForward(SUCCESS);
    }
}
